import 'package:dio/dio.dart';
import 'package:puppy_store/service/requests.dart';
import 'package:puppy_store/models/category_model.dart';

class CategoryApi {
  // 获取一级分类数据
  static Future<List<PrimaryCategoryModel>> getPrimaryCategory() async {
    Response res = await PuppyRequestManager().handleRequest(
      '/home/category/head/app',
      'GET',
    );

    dynamic result = res.data['result'];

    List<PrimaryCategoryModel> primaryCategoryModel = [];

    for (var item in result) {
      primaryCategoryModel.add(PrimaryCategoryModel.fromJson(item));
    }

    return primaryCategoryModel;
  }

  // 获取二级分类数据
  static Future<SecondaryCategoryModel> getSecondaryCategory(String id) async {
    String path = "/category?id=$id";
    Response res = await PuppyRequestManager().handleRequest(path, 'GET');

    dynamic result = res.data['result'];

    SecondaryCategoryModel secondaryCategoryModel =
        SecondaryCategoryModel.fromJson(result);

    return secondaryCategoryModel;
  }
}
